// In this example I show you how you can build a single pulse with circular polarization 
// in the x and y directions Ex and Ey
// Alexis A. Chacón Salazar April, 8th 2011

#include <iostream>
#include <complex>
#include<math.h>
#include <string>
#include "laser.h"

using namespace std;

int main()
{   	
	FILE *out0, *out1, *out2, *out3, *out4;
	FILE *out5, *out6, *out7, *out8, *out9; 
	
	out0=fopen("out0.txt","w");
	out1=fopen("out1.txt","w");
	/*
	out2=fopen("out2.txt","w");
	out3=fopen("out3.txt","w");
	
	out4=fopen("out4.txt","w");
	out5=fopen("out5.txt","w");
	 */
	
	/***=============================
	 ================================
	  Using the laser pulses librery 
	 ================================
	 ============================****/

	// PARAMETERS TO BUILD LASER PULSE
	
	int Npulses= 1;	                       // Total number of pulses 
	
	string env_name ="rsin2";              /**** 
												IMPORTANT: The Name of the envelope, may be: 
											               konst, rect, sin2, gauss or rsin2.
											****/ 
	
	double t01 = 0.0;						// Start time of the first pulse
	double dt     = 0.05;					// Time step
	double blaser = 50.0;					// Time before the pulse atomic unit
	double alaser = 50.0;					// Time after the pulse atomic unit (a.u.)
	
	laser fpulse(Npulses);					// Creator of Laser Pulses
		
	//First pulse Laser
	fpulse.I0[0]      = 1.0e13;				// Intensity W/cm^2 
	fpulse.w0[0]      = 0.057;				// Central frequency in a.u.
   	fpulse.cycles0[0] = 6;					// Cycles number

	
	/*** The condition to circular polarization for the electric field pulse are:
	     I.  the elliptical parameter is fpulse.e[0]=1;
		 II. the relative phase between Ex and Ey component is 
	     fpulse.phi_rel[0] = pi/2.0 ***/
	
	fpulse.e[0]       = 1.00;				// Elliptical of the pulse	
   	fpulse.cep0[0]    = 0.0;				// Carrier Envelope Phase
	fpulse.phi_rel[0] = pi/2.0;				// Relative phase between the polarization Ex and Ey
	
	
	double periodIR = dospi/fpulse.w0[0];	// Period in a.u.

	//fpulse.delay0[0]  = 0.0;				// Delay in a.u.	

	fpulse.envelope=env_name;               // Envelope name
	
	
	cout << "\n"<<fpulse.envelope<<endl;

   	fpulse.laser_pulses(dt, t01, blaser, alaser);  // Making the circular polarization of the pulse Ex & Ey
		
	// Save the laser pulse
	for (int ktime=0; ktime<fpulse.g.n; ktime++)
		fprintf(out0,"%e %e %e %e %e\n",
				fpulse.g.t[ktime],
				fpulse.efield.f[ktime][0], fpulse.avector.f[ktime][0],
				fpulse.efield.f[ktime][1], fpulse.avector.f[ktime][1]);
    //End save the laser pulse
	
		
    //**** Note1:
	//****      fpulse.g.t[ktime] is the k-th instant of the time
	//****      fpulse.efield.f[ktime][0] is the Ex-ktime component of the electric field of the laser pulse
	//****      fpulse.efield.f[ktime][1] is the Ey-ktime component of the electric field of the laser pulse
	//****      fpulse.avector.f[ktime][0] is the Ax-ktime component of the vector potential of the laser pulse 
	//****      fpulse.avector.f[ktime][1] is the Ay-ktime component of the vector potential of the laser pulse 

	
	// Save the envelope
	for (int ktime=0; ktime<fpulse.g.n; ktime++)
		fprintf(out1,"%e %e %e\n",
				fpulse.g.t[ktime],
				fpulse.env[0].f[ktime][0], fpulse.env[0].f[ktime][1]);
    //End save the envelope	

	
    //**** Note2:
	//****      fpulse.env[0].f[ktime][0] is the envelope Ex-ktime component of the electric field of the laser pulse
	//****      fpulse.env[0].f[ktime][1] is the envelope Ey-ktime component of the electric field of the laser pulse


	/***===========================
	 ==============================***/
	
	
	fclose(out0);
	fclose(out1);   
	/*fclose(out2);
	fclose(out3);
	fclose(out4);
	fclose(out5);*/
	
	
}//End main

